// pages/bank/bank.js
const app = getApp(),util=require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    bank:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getBank()
  },

  /**
   * 生命周期函数--监听页面显示
   */
   onShow(){
    let type = wx.getStorageSync('type')
    if(app.globalData.userInfo == null){
      this.setData({
        why:true,
        content:'请您先登录',
        to:1,
        togo:'登录'
      })
    }
    // else if(type !=2){
    //   this.setData({
    //     why:true,
    //     content:'请先完善个人信息',
    //     to:2,
    //     togo:'完善信息'
    //   })
    // }
    else{
      this.setData({
        why:false,
      })
    }
    this.getJobList()
  },
  onReady(){
    
  },
  cancel(){
    wx.switchTab({
      url: '/pages/my/my',
    })
  },
  loginAgain(){
    if(this.data.to==1){
      wx.switchTab({
        url: '/pages/my/my',
      })
    }else if(this.data.to==2){
      
        wx.navigateTo({
          url: '/pages/authentication/authentication',
        })
     
    }
  },
  getJobList(){
    let that=this;
    wx.request({
      url: app.globalData.url+'standard/achievementList',
      method:'POST',
      success(res){
        console.log(res,'职位列表')
        if(res.statusCode==200 && res.data.code==1){
          that.setData({
            jobList:res.data.data.list
          })
        }
      },
      fail(res){}
    })
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  getBank(){
    let that = this
    util.post('bankurl/cardlist',{},function(res){
      console.log(res)
      let list = res.data.msg

      list.forEach(item=>{

        let front = item.bank_id.substring(0,4)
        let behind = item.bank_id.substring(item.bank_id.length-4,item.bank_id.length)

        item.front = front
        item.behind = behind
      })

      that.setData({
        list
      })
    })
  },
  del(e){
    let that = this
    console.log()
    let bankcard = e.currentTarget.dataset.item.bank_id
    wx.showModal({
      title:'提示',
      content:'确认删除',
      confirmColor:'#28AA85',
      success:function(res){
        if(res.confirm){
            util.post('bankurl/carddelete',{bankcard},function(res){
            that.getBank()
          })
        }
      }
    })
    
  },
  toAdd(){
    wx.navigateTo({
      url: '../../pages/addBank/addbank',
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})